<?php
	class binhluandb
	{
		public function Add($MaBaiViet, $MaNguoiDung, $NoiDungBinhLuan, $ThoiGianBinhLuan)
		{
			$sql = "INSERT INTO `tbl_binhluan`(`MaBaiViet`, `MaNguoiDung`, `NoiDungBinhLuan`, `ThoiGianBinhLuan`) 
					VALUES ($MaBaiViet, $MaNguoiDung, '$NoiDungBinhLuan', now())";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Delete($MaBinhLuan)
		{
			$sql = "DELETE FROM `tbl_binhluan` WHERE MaBinhLuan = $MaBinhLuan";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function GetList($MaBaiViet)
		{
			$sql = "SELECT tbl_binhluan.MaBinhLuan, tbl_binhluan.NoiDungBinhLuan, tbl_binhluan.ThoiGianBinhLuan, tbl_nguoidung.TenNguoiDung, tbl_binhluan.MaNguoiDung 
					FROM `tbl_binhluan`, `tbl_nguoidung`, `tbl_noidungtin` 
					WHERE tbl_nguoidung.MaNguoiDung = tbl_binhluan.MaNguoiDung 
							AND tbl_binhluan.MaBaiViet = tbl_noidungtin.MaBaiViet 
							AND tbl_binhluan.MaBaiViet = $MaBaiViet 
					ORDER BY tbl_binhluan.ThoiGianBinhLuan DESC LIMIT 0, 5";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
	}
?>